package com.hzit.manager.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.hzit.manager.entity.SpecGroup;
import com.ruoyi.system.api.domain.Specification;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.hzit.manager.service.ISpecificationService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 规格管理Controller
 * 
 * @author hbxfwf
 * @date 2024-03-07
 */
@RestController
@RequestMapping("/specification")
public class SpecificationController extends BaseController
{
    @Autowired
    private ISpecificationService specificationService;

    /**
     * 查询规格管理列表
     */
        @GetMapping("/list")
    public TableDataInfo list(Specification specification)
    {
        startPage();
        List<Specification> list = specificationService.selectSpecificationList(specification);
        return getDataTable(list);
    }

    /**
     * 导出规格管理列表
     */
        @Log(title = "规格管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Specification specification)
    {
        List<Specification> list = specificationService.selectSpecificationList(specification);
        ExcelUtil<Specification> util = new ExcelUtil<Specification>(Specification.class);
        util.exportExcel(response, list, "规格管理数据");
    }

    /**
     * 获取规格管理详细信息
     */
        @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        SpecGroup specGroup = specificationService.selectSpecGroupById(id);
        return AjaxResult.success("获取规格成功!",specGroup);
    }

    /**
     * 新增规格管理
     */
        @Log(title = "规格管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SpecGroup specGroup)
    {
        System.out.println("specGroup = " + specGroup);
        return toAjax(specificationService.addSpec(specGroup));
    }

    /**
     * 修改规格管理
     */
        @Log(title = "规格管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SpecGroup specGroup)
    {
        return toAjax(specificationService.updateSpec(specGroup));
    }

    /**
     * 删除规格管理
     */
        @Log(title = "规格管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(specificationService.deleteSpecificationByIds(ids));
    }
}
